package com.sinosoft.ci.patch.yqscm;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

abstract class AbstractYQScmFileExtractRow {
	private Row sheetRow;

	public AbstractYQScmFileExtractRow(Row sheetRow) {
		this.sheetRow = sheetRow;
	}
	
	/**
	 * 改行是否是个有效行
	 */
	public boolean isValid() {
		Cell fileCell = getFileCell();
		if (fileCell == null) {
			return false;
		}

		String fileCellVal = fileCell.getStringCellValue();
		if (fileCellVal.trim().isEmpty()) {
			return false;
		}
		if (fileCellVal.toLowerCase().endsWith(".class")) {
			return false;
		}

		return true;
	}

	/**
	 * 获取源码条目文件后缀名
	 * 
	 * @return
	 */
	public String getEntryType() {
		Cell fileCell = getFileCell();
		if (null == fileCell) {
			return null;
		}

		String fileName = fileCell.getStringCellValue().toLowerCase();
		if (fileName.indexOf(".") == -1) {
			return "file";
		}
		String type = fileName.substring(fileName.lastIndexOf(".") + 1);
		return type.toLowerCase();
	}

	public abstract String getSrcEntryPath();

	public String getFileName() {
		Cell cell = getFileCell();
		return cell == null ? null : cell.getStringCellValue();
	}
	
	protected Row getSheetRow() {
		return sheetRow;
	}

	protected Cell getFileCell() {
		if (null == sheetRow) {
			return null;
		}

		return sheetRow.getCell(2);
	}
}
